package com.linkage.event.controller;

import cn.hutool.json.JSONUtil;
import com.linkage.common.base.RequestInfo;
import com.linkage.common.base.ResponseInfo;
import com.linkage.event.pojo.entity.EventMessage;
import com.linkage.event.service.EventBossOperationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Slf4j
@RestController
@RequestMapping(value = "/operateEvent")
public class OperateEventController {

    @Autowired
    private EventBossOperationService eventBossOperationService;

    /**
     * 修改事件信息
     * @param emRequestInfo
     * @return
     */
    @RequestMapping(value = "/updateEvent", method = RequestMethod.POST)
    public String updateEventMessage(@RequestBody RequestInfo<EventMessage> emRequestInfo){
        try {
            this.eventBossOperationService.updateEventMessage(emRequestInfo.getBuss());
            return JSONUtil.toJsonStr(ResponseInfo.success());
        } catch (Exception e) {
            log.error("",e);
            return JSONUtil.toJsonStr(ResponseInfo.error(e.getMessage()));
        }

    }


    /**
     * 删除事件信息
     * @param eventMessage
     * @return
     */
    @RequestMapping(value = "/deleteEvent", method = RequestMethod.POST)
    public String deleteEventMessage(@RequestBody RequestInfo<Map> eventMessage){
        try {
            this.eventBossOperationService.deleteEventMessage(eventMessage.getBuss().get("eventMessageId").toString());
            return JSONUtil.toJsonStr(ResponseInfo.success());
        } catch (Exception e) {
            log.error("",e);
            return JSONUtil.toJsonStr(ResponseInfo.error(e.getMessage()));
        }
    }

}
